package data_base;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import data_base.DataConnection;

public class searches {

	// busca una cancion introduciendo el string del titulo
	// devuelve el codigo de cancion(se puede cambiar)

	public static String busquedaRuta(String titulo) {
		String resultado = null;
		Statement statement = null;
		ResultSet rs = null;
		Connection conn = null;
		try {
			conn = DataConnection.openConection();

			String query = "SELECT ruta FROM CANCION WHERE TITULO='" + titulo
					+ "'";

			statement = conn.createStatement();

			rs = statement.executeQuery(query);

			resultado = rs.getString("ruta");

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {

			try {
				statement.close();
				rs.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		return resultado;

	}

	// busqueda de los albumes

	@SuppressWarnings("null")
	public static ArrayList<String> albumes() {

		ArrayList<String> listaAlbumes = new ArrayList<String>();
		Statement statement1 = null;
		ResultSet rs = null;
		Connection conn = null;
		try {
			conn = DataConnection.openConection();

			String query = "SELECT DISTINCT album FROM CANCION";
			statement1 = conn.createStatement();

			rs = statement1.executeQuery(query);

			while (rs.next()) {

				String resultado = rs.getString("album");

				listaAlbumes.add(resultado);
			}
			return listaAlbumes;
		} catch (SQLException e) {
			System.out.println("no values found");
		} finally {
			try {
				statement1.close();
				rs.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
		return listaAlbumes;

	}

	@SuppressWarnings("null")
	public static ArrayList<String> artistas() {

		ArrayList<String> listaArtistas = new ArrayList<String>();
		Statement statement1 = null;
		ResultSet rs = null;
		Connection conn = null;
		try {
			conn = DataConnection.openConection();

			String query = "SELECT DISTINCT artista FROM CANCION";
			statement1 = conn.createStatement();

			rs = statement1.executeQuery(query);

			while (rs.next()) {
				listaArtistas.add(rs.getString("artista"));
			}

		} catch (SQLException e) {
			System.out.println("no values found");
		} finally {
			try {
				statement1.close();
				rs.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
		return listaArtistas;

	}

	public static ArrayList<String> genero() {

		ArrayList<String> listaGenero = new ArrayList<String>();
		Statement statement1 = null;
		ResultSet rs = null;
		Connection conn = null;
		try {
			conn = DataConnection.openConection();

			String query = "SELECT DISTINCT genero FROM CANCION";
			statement1 = conn.createStatement();

			rs = statement1.executeQuery(query);

			while (rs.next()) {
				listaGenero.add(rs.getString("genero"));
			}

		} catch (SQLException e) {
			System.out.println("no values found");
		} finally {
			try {
				statement1.close();
				rs.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
		return listaGenero;

	}

	// busqueda de las canciones en funcion de su album

	public static void main(String[] args) {

	}
}
